Provider.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 2
Metric Value
cc 1
c 5
b 0
f 2
nc 1
dl 0
loc 13
rs 9.4285
nop 0
1
import { Children, Component } from 'react';
2
import PropTypes from 'prop-types';
3
import createRouteToLocationParser from '../parsers/routeToLocation';
4
import { DEFAULT_SLICE, __DEV__ } from '../constants';
5
6
class Provider extends Component {
7
    getChildContext() {
8
9
        const { immutable, slice, routes, current } = this.props;
10
        const router = {
11
            immutable,
12
            slice,
13
            routes,
14
            parseRoute: createRouteToLocationParser(routes),
15
            current
16
        };
17
18
        return { router };
19
    }
20
21
    render() {
22
        return Children.only(this.props.children);
23
    }
24
}
25
26
Provider.childContextTypes = {
27
    router: PropTypes.shape({
28
        slice: PropTypes.string,
29
        immutable: PropTypes.bool,
30
        routes: PropTypes.array
31
    }).isRequired
32
};
33
34
Provider.defaultProps = {
35
    immutable: false,
36
    slice: DEFAULT_SLICE,
37
    routes: [],
38
    current: ''
39
};
40
41
if (__DEV__) {
42
    Provider.propTypes = {
43
        immutable: PropTypes.bool.isRequired,
44
        slice: PropTypes.string.isRequired,
45
        routes: PropTypes.array.isRequired,
46
        current: PropTypes.string.isRequired,
47
        children: PropTypes.oneOfType([
48
            PropTypes.element,
49
            PropTypes.arrayOf(PropTypes.element),
50
            PropTypes.string
51
        ])
52
    };
53
}
54
55
export default Provider;
56